package com.example.works;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.Gravity;
import android.widget.Toast;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
    private String state = "";
    private static final String StringTAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        showState();
        Log.d(StringTAG, "onCreate()");
    }

    private void showState(){
        String strState = new Throwable().getStackTrace()[1].getMethodName()
                + "：" + new Throwable().getStackTrace()[2].getMethodName();
        state = state + strState + "-->\n";
        Toast toast = Toast.makeText(getApplicationContext(), state, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.TOP, 0, 200);
        toast.show();
    }

    @Override
    public void onStart(){
        super.onStart();
        showState();
        Log.d(StringTAG, "onStart()");
    }

    @Override
    public void onRestart(){
        super.onRestart();
        showState();
        Log.d(StringTAG, "onRestart()");
    }

    @Override
    public void onResume(){
        super.onResume();
        showState();
        Log.d(StringTAG, "onResume()");
    }

    @Override
    public void onPause(){
        super.onPause();
        showState();
        Log.d(StringTAG, "onPause()");
    }

    @Override
    public void onStop(){
        super.onStop();
        showState();
        Log.d(StringTAG, "onStop()");
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
        showState();
        Log.d(StringTAG, "onDestroy()");
    }
}